from django.db import models

# Create your models here.
class Hostel(models.Model):
    name = models.CharField(max_length=250)

    def __str__(self):
        return self.name

    class Meta:
        db_table = "hostel"
        verbose_name = "Hostel"
        verbose_name_plural = "Hostels"

class Room(models.Model):
    hostel = models.ForeignKey(Hostel, on_delete=models.CASCADE,related_name='room_hostel',
                               db_constraint=False,verbose_name='Room')
    name = models.CharField(max_length=250)
    price = models.IntegerField()
    image = models.ImageField(upload_to='avatar/')
    display = models.BooleanField(default=True,blank=True)
    time = models.CharField(max_length=250,verbose_name='使用时间',null=True,blank=True)

    def __str__(self):
        return self.name

    class Meta:
        db_table = "room"
        verbose_name = "Room"
        verbose_name_plural = "Rooms"


class Reservation(models.Model):
    room = models.ForeignKey(Room, on_delete=models.DO_NOTHING,related_name='reservation_room',
                               db_constraint=False,verbose_name='Room')
    name = models.CharField(max_length=250)
    phone = models.CharField(max_length=250)
    price = models.IntegerField(default=None,null=True,blank=True)
    message = models.TextField()
    time = models.CharField(max_length=250, verbose_name='使用时间', null=True, blank=True)


    def __str__(self):
        return self.name

    class Meta:
        db_table = "reservation"
        verbose_name = "Reservation"
        verbose_name_plural = "Reservations"